<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/font-awesome.min.css">
    <style>
        .layui-form-item .layui-form-label{
            width: 120px;
        }
        .layui-form-item .layui-textarea{
            width: 190px;
        }
        #phone-one-div {display: none}
    </style>
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
          <input type="hidden" name="status" value="{:input()['status']}">
          <div class="layui-form-item">
              <label for="activity" class="layui-form-label">
                  赛事名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="activity" name="activity" lay-verify="required" required="" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  客户姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
              </div>
          </div>

          <div class="layui-form-item layui-form-text">
            <label for="address" class="layui-form-label">地区(市、县)</label>
              <div class="layui-input-inline">
                  <input type="text" id="address" name="address" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div  id="phones-div">
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  主要联系电话
              </label>
              <div class="layui-input-inline">
                  <input type="text" oninput="value=value.replace(/[^\d]/g,'')" id="phone" name="phone[]" placeholder="请至少填写一种联系方式.." value="" autocomplete="off" class="layui-input" >
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <a href="javascript:;" id="phone-add-btn"><i class="fa fa-plus"></i></a>
              </div>
          </div>
          </div>
          <div class="layui-form-item">
              <label for="wx" class="layui-form-label">
                  微信号
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="wx" name="wx" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red"></span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="wx_code" class="layui-form-label">
                  微信二维码
              </label>
              <div class="layui-input-inline">
                <button type="button" class="layui-btn " id="wx_code_btn">上传微信二维码</button>
                <img src="" id="wx_code_preview">
                <input type="hidden" id="wx_code" name="wx_code"  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red"></span>
              </div>
          </div>

          {if condition="input()['status'] eq 4"}
          <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>签单资料</legend>
          </fieldset>
          <div class="layui-form-item">
            <label for="username" class="layui-form-label">
              合同图片
            </label>
            <div class="layui-input-block">
                <button type="button" style="width: 140px;" class="layui-btn layui-btn-sm layui-btn-normal" id="uploads"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                <img id="img" src="" width="140px" style="margin-top: 5px;display: block;">
                <input type="hidden" name="hetong" id="hetong" value="" />
            </div>
          </div>
          <!-- <div class="layui-form-item">
              <label for="live_id" class="layui-form-label">
                  <span class="x-red">*</span>直播id
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="live_id" name="live_id" required="" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>海豚直播后台创建链接后的链接id
              </div>
          </div> -->

          <div class="layui-form-item">
              <label for="company_name" class="layui-form-label">公司名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="company_name" name="company_name" autocomplete="off" class="layui-input">
              </div>

          </div>

          <div class="layui-form-item">
              <label for="ratio" class="layui-form-label">
                  <span class="x-red">*</span>合作分成
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="ratio" name="ratio" required="" lay-verify="required" autocomplete="off" class="layui-input">
              </div>

          </div>
          <div class="layui-form-item">
              <label for="cashing_fee" class="layui-form-label">
                  <span class="x-red">*</span>提现手续费
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="cashing_fee" name="cashing_fee" required="" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
          </div>
          {/if}
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button type="button" class="layui-btn" lay-filter="add" lay-submit="">
                  确定新增
              </button>
          </div>
      </form>
    </div>
<div id="phone-one-div">
<div class="layui-form-item">
    <label for="phone" class="layui-form-label">
        其他电话
    </label>
    <div class="layui-input-inline">
        <input type="text" oninput="value=value.replace(/[^\d]/g,'')"  name="phone[]"  value="" autocomplete="off" class="layui-input" >
    </div>
    <div class="layui-form-mid layui-word-aux">
        <a href="javascript:;" onclick="$(this).parent().parent().remove()" class="phone-del-btn"><i class="fa fa-times"></i></a>
    </div>
</div>
</div>
    <script>
        layui.use(['form','layer','laydate','upload'], function(){
          $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer
          ,laydate = layui.laydate
          ,upload = layui.upload;

          var phoneDiv = $('#phone-one-div').html();
          $('#phone-add-btn').click( function(){
            if($("input[name='phone[]']").length < 10)
            {
              $('#phones-div').append(phoneDiv);
            }
          })


        upload.render({
          elem: '#wx_code_btn'
          ,url: '{:url('ds/upload',["folder"=>"clientwxcode"])}' 
          ,accept: 'images'
          ,before: function(obj){
            obj.preview(function(index, file, result){
              $('#wx_code_preview').attr('src', result); 
            });
            layer.msg('上传中', {icon: 16, time: 0});
          }
          ,done: function(res){
            if(res.code > 0){
              $('#wx_code_preview').attr('src', '');
              $('#wx_code').val('');
              return layer.msg('上传失败');
            }else{ 
              $('#wx_code').val(res.filename)
              layer.msg('上传成功');
            }
          }
        });

          var uploadInst = upload.render({
              elem: '#uploads'
              , url: '{:url("Client/upload")}'
              , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result){
                    //如果有图片再点击上传就撤销原来的图片
                    var img=$("#img").attr("src");
                    var imgurl=$("#hetong").val();
                    if(img){
                        $.ajax({
                            type:"post",
                            dataType:"json",
                            data:{imgurl:imgurl},
                            url:"{:url('Client/cancel')}",
                            success:function(data){
                            }
                        });
                    }
                    $('#img').attr('src', result); //图片链接(base64)
                });
              }
              , done: function (res) {
                  //如果上传失败
                  if (res.code == 0) {
                      return layer.msg(res.err);
                  }
                  //上传成功
                  if(res.code == 1) {
                      $('#hetong').attr('value','/uploads/hetong/'+res.savename);
                  }
              }
          });
          //自定义验证规则
          form.verify({
            activity: function(value){
              if(value.length < 2){
                return '活动名称至少2个字';
              }
            }
          });

          //年月选择器
            laydate.render({ 
              elem: '#activity_time'
              //,type: 'month'
            });

          //监听提交
          form.on('submit(add)', function(data){
            //console.log(data);
            if(!data.field.wx_code && !data.field.wx && !$('#phone').val() ){
              layer.msg('最少填写一项联系方式');
              return false;
            }
            
            $.ajax({
                type:'POST',
                dataType:'json',
                data:{data:data.field},
                url:"{:url('Client/add')}",
                success:function(obj){
                    console.log(obj);
                    if(obj.apply==1)
                    {
                        layer.alert(obj.msg,{icon: obj.icon},function(){
                            window.location.href = "{:url('Apply/clientAdd')}?dataJson="+obj.dataJson
                        }); 
                        
                    }
                    else
                    {
                      layer.alert(obj.msg, {icon: obj.icon},function(){
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        // 可以对父窗口进行刷新 
                        x_admin_father_reload();
                      });    
                    }

                }
            });
            return false;
          });
          
          
        });
    </script>
  </body>

</html>